<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>表单数据绑定</title>
    <script type="text/javascript" src="js/react.development.js"></script>
    <script type="text/javascript" src="js/react-dom.development.js"></script>
    <script type="text/javascript" src="js/babel.min.js"></script>
</head>
<body>
    <div id="root">
    
    </div>
    <script type="text/babel">
        class Myform extends React.Component{
            constructor(props) {
                super(props);
                this.state = {
                    username:'',
                    password:'',
                };
            }

            inputFn = (e)=>{
                // Prevents React from resetting its properties:
                e.persist();
                console.log(e);
                this.setState({
                    [e.target.name]:e.target.value,
                })
            }

            render() {
                return (
                    <form>
                        <h2>用户登录</h2>
                        <div>
                            用户名：<input onChange={this.inputFn} type="text" name="username" id=""/>{this.state.username} 
                        </div>
                        <br/>
                        <div>
                            密&nbsp;&nbsp;&nbsp;码：<input onChange={this.inputFn} type="password" name="password" id=""/>{this.state.password} 
                        </div>
                    </form>
                )
            }
        }
        ReactDOM.render(<Myform/>, document.getElementById('root'));
    </script>
</body>
</html>